package com.m4u.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

@Entity
@NamedQueries( { @NamedQuery(name = Cliente.LIST_ALL, query = "select c from Cliente c") })
@TableGenerator(name = "CLIENTE_ID", pkColumnValue = "CLIENTE_ID", allocationSize = 1)
public class Cliente implements Serializable {

    private static final long serialVersionUID = 0;

    public static final String LIST_ALL = "Cliente.listAll";

    @Version
    @Temporal(TemporalType.TIMESTAMP)
    private Date version = new Date();

    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "CLIENTE_ID")
    private int id = 0;

    @Column(length = 50)
    private String nome = null;

    @Temporal(TemporalType.TIMESTAMP)
    private Date data = null;

    @Column(nullable = true, columnDefinition = "numeric(15,2)")
    private Double valor = 0.0;

    // @OneToOne(fetch = FetchType.LAZY, mappedBy = "cliente")
    transient private ClienteImage clienteImage;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinTable(name = "cliente_telefone", joinColumns = { @JoinColumn(name = "cliente_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "telefone_id", referencedColumnName = "id") })
    private Set<Telefone> telefones = new HashSet<Telefone>();

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinTable(name = "cliente_telefone_cel", joinColumns = { @JoinColumn(name = "cliente_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "telefone_id", referencedColumnName = "id") })
    private Set<Telefone> telefonesCel = new HashSet<Telefone>();

    public Set<Telefone> getTelefonesCel() {
        return telefonesCel;
    }

    public ClienteImage getClienteImage() {
        return clienteImage;
    }

    public void setClienteImage(ClienteImage clienteImage) {
        this.clienteImage = clienteImage;
    }

    public Set<Telefone> getTelefones() {
        return telefones;
    }

    public int getId() {
        return id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public Date getData() {
        return data;
    }

    public void setData(Date data) {
        this.data = data;
    }

    public Double getValor() {
        return valor;
    }

    public void setValor(Double valor) {
        this.valor = valor;
    }

    public Date getVersion() {
        return version;
    }

}
